package com.gxa.service.impl;

import com.gxa.common.R;
import com.gxa.mapper.SkdMapper;
import com.gxa.pojo.*;
import com.gxa.service.SkdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Author: zxy
 * Date: 2021/12/06 9:37
 * Description:
 * Version: V1.0
 */
@Service
public class SkdServiceImpl implements SkdService{
    @Autowired(required = false)
    private SkdMapper skdMapper;
    @Override
    public R queryClient(int param1, int param2) {
        List<Customer> list = skdMapper.queryClient(param1,param2);
        R r = new R();
        if(list!=null){
            r.setCode(200);
            r.setData(list);
            r.setMsg("成功");
        }else {
            r.setCode(403);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R queryPayPerson() {
        List<Account_Manage> list = skdMapper.queryPayPerson();
        R r = new R();
        if(list!=null){
            System.out.println();
            r.setCode(200);
            r.setData(list);
            r.setMsg("成功");
        }else {
            r.setCode(403);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R queryPayType() {
        List<Settlement_Type> list = skdMapper.queryPayType();
        R r = new R();
        if(list!=null){
            r.setCode(200);
            r.setData(list);
            r.setMsg("成功");
        }else {
            r.setCode(403);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R queryYD(String clientName,String beginDate,String endDate,String msg) {
        List<Receipt_Sales> list = skdMapper.queryYD(clientName,beginDate,endDate,msg);
        R r = new R();
        if(list!=null){
            r.setCode(200);
            r.setData(list);
            r.setMsg("成功");
        }else {
            r.setCode(403);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R addSKD(SkdOrFkd skdOrFkd) {
        //将前端数据取出来
        //先将外表拿出来
        Receipt_Pay receipt_pay = skdOrFkd.getReceipt_pay();
        //获取外表的主键，后面要将其作为外键插入到子表中
        String receipt_pay__id = receipt_pay.getReceipt_Pay__Id();
        //获取子表
        List<Payaccount> payaccounts = receipt_pay.getPayaccounts();
        //获取源单表
        List<Receipt_Sales> receipt_sales = skdOrFkd.getReceipt_sales();
        //先将主表插入数据库
        int ins = skdMapper.insMsg(receipt_pay);
        //将子表插入数据库
        //将所需要的数据传入
        int insSon = skdMapper.insSon(payaccounts,receipt_pay__id);
        int update = skdMapper.update(receipt_sales,receipt_pay__id);
        return null;
    }
}
